﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace matrixdotnet.Common
{
    public struct PositiveValue<T> where
        T : struct, IComparable<T>
    {
        private T value;

        public PositiveValue(T value)
        {
            if (value.CompareTo(new T()) <= 0)
                throw new ArgumentOutOfRangeException();

            this.value = value;
        }

        public T Value
        {
            get
            {
                return value;
            }
            set
            {
                if (value.CompareTo(new T()) <= 0)
                    throw new ArgumentOutOfRangeException();

                this.value = value;
            }
        }

        public static implicit operator T(PositiveValue<T> pv)  // implicit to T conversion operator
        {
            return pv.Value;  // implicit conversion
        }
    }
}
